package com.sbr.seb.wicket.page.administration;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import org.apache.wicket.extensions.yui.calendar.DatePicker;
import org.apache.wicket.markup.html.form.ChoiceRenderer;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.RequiredTextField;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sbr.seb.entity.alter.Schema;
import com.sbr.seb.entity.alter.enumeration.AlterAction;
import com.sbr.seb.wicket.page.BasePage;

public class AddAlter extends BasePage {

	private static final long serialVersionUID = 1L;
	protected static final Logger logger = LoggerFactory.getLogger(AddAlter.class);
	private String alterActionName;
	private String alterSchemaName;
	
	public AddAlter() {
		super();
		
		List<Schema> schemaList = new ArrayList<Schema>();
		schemaList.add(new Schema(0, "Administre"));
		schemaList.add(new Schema(1, "Commun"));

		final TextField<Object> alterNameText = new RequiredTextField("alterName", new Model());
		final TextField<Object> alterInstanceText = new RequiredTextField("alterInstance", new Model());
		
//		final TextField<Object> alterActionText = new RequiredTextField("alterAction", new Model());
//		final TextField<Object> alterSchemaText = new RequiredTextField("alterSchema", new Model());
		final TextField<Object> alterInstallationDateText = new RequiredTextField("alterInstallationDate", Date.class);
		alterInstallationDateText.add(new DatePicker());
		final TextField<Object> alterDescriptionText = new RequiredTextField("alterDescription", new Model());

		final DropDownChoice<AlterAction> actionBox = new DropDownChoice<AlterAction>("alterActionBox", new PropertyModel(this, "alterActionName"), Arrays.asList(AlterAction.values()),  new ChoiceRenderer<AlterAction>("name","name"));
		final DropDownChoice<Schema> schemaBox = new DropDownChoice<Schema>("alterSchemaBox", new PropertyModel(this, "alterSchemaName"), schemaList,  new ChoiceRenderer<Schema>("name","id"));
		
		Form form = new Form("addAlterForm") {

			@Override
			protected void onSubmit() {
				logger.debug("onSubmit called");
			}
		};
		form.add(alterNameText);
		form.add(alterInstanceText);
		form.add(actionBox);
		form.add(schemaBox);
		form.add(alterInstallationDateText);
		form.add(alterDescriptionText);
		
		add(form);
		add(new FeedbackPanel("feedbackPanel"));
	}

}
